package xyz.mkkbjb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import xyz.mkkbjb.comment.ResponseResult;
import xyz.mkkbjb.pojo.TuLingAiAnswer;
import xyz.mkkbjb.pojo.UserInfo;
import xyz.mkkbjb.service.TuLingAiService;
import xyz.mkkbjb.utils.result.ResultSet;

@Controller
public class TuLingAiController {
	@Autowired
	private TuLingAiService tuLingAiService;
	@RequestMapping("/QTA")
	
	@ResponseBody
	public ResponseResult<String> getAnswer(Model model,@RequestParam(value="question")String q,@RequestParam(value="pageId")String pageId){
		if (q == null || pageId == null) {
			ResponseResult<String> makeRsp = ResultSet.makeRsp(403, "暂无权限");
			return makeRsp;
		}
		UserInfo userInfo = new UserInfo();
		userInfo.setUserId(pageId);
		TuLingAiAnswer saveAiAnswer = tuLingAiService.saveAiAnswer(q, 0, userInfo);
		ResponseResult<String> makeRsp = ResultSet.makeRsp(saveAiAnswer.getAnswerCode(), saveAiAnswer.getAnswer());
		return makeRsp;
	}
}
